from django.core.management.base import BaseCommand
from faker import Faker
from realize.models.AirLineData import AirLineData
from realize.models.station import Station
import random


# mock 基站数据
class Command(BaseCommand):
    help = 'Closes the specified poll for voting'

    def add_arguments(self, parser):
        parser.add_argument('number', type=int)

    def handle(self, *args, **options):
        number = options['number']
        for i in range(number):
            air = AirLineData()
            fake = Faker('zh_CN')
            station = random.choice(Station.objects.all())

            air.origin_airport = fake.address()
            air.destination_airport = fake.address()
            air.by_station = station
            pre, sub = station.location.split(',')
            spre, ssub = str(float(pre) + 0.00145), str(float(sub) + 0.00055)
            air.location = spre + ',' + ssub

            air.save()
            self.stdout.write("ADD ----- OK")
        self.stdout.write(f"Total: {number} messages added!!!")
